import React from 'react'
import { InboxOutlined } from '@ant-design/icons'
import type { UploadProps } from 'antd'
import { Upload } from 'antd'

const { Dragger } = Upload

interface MyUplodProps {
    change?: (file_info: any) => void
}

const MyUpload: React.FC<MyUplodProps> = (props: any) => {
    // console.log(change)
    const config: UploadProps = {
        name: 'file',
        onChange(info) {
            // console.log('change', info)
            props?.change(info)
        },
        onDrop(e) {
            console.log('Dropped files', e.dataTransfer.files)
        },
        customRequest(option: any) {
            const urlData = URL.createObjectURL(option.file) //转为blob格式(二进制文件)
            console.log('blob', urlData)
            option.onScuucess()
        },
        maxCount: 1,
        beforeUpload: () => {
            return false
        },
        multiple: true
    }

    return (
        <Dragger {...config}>
            <p className=''>
                <InboxOutlined />
            </p>
            <p className='ant-upload-text'>点击或者上传图标</p>
            <p className='ant-upload-hint'>请上传图片</p>
        </Dragger>
    )
}

export default MyUpload
